package com.sylli.oeuf.server.game.logic.skill;

import java.util.ArrayList;
import java.util.Collection;

import com.sylli.oeuf.server.game.logic.ActionProduct;
import com.sylli.oeuf.server.game.logic.BattleActor;
import com.sylli.oeuf.server.game.logic.CastingTarget;
import com.sylli.oeuf.server.game.logic.EventParameter;
import com.sylli.oeuf.server.game.logic.Skill;
import com.sylli.oeuf.server.game.logic.action.CombatLog;
import com.sylli.oeuf.server.game.logic.action.ConsumeMana;
import com.sylli.oeuf.server.game.logic.action.Damage;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueElement;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueFlag;
import com.sylli.oeuf.server.game.logic.invocation.EnoughMPInvocationCondition;
import com.sylli.oeuf.server.game.logic.invocation.InvocationAction;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEntry;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEvent;

public class Exorcist_Bane extends Skill {
	
	public Exorcist_Bane() {
		super("bane", CastingTarget.FocusTarget);
		getEntries().put(
			InvocationEvent.STD_IE_ON_ACTIVE,
			new InvocationEntry(
					new EnoughMPInvocationCondition() {

						@Override
						public int getAgainstValue(int rank) {
							return computeManaUse(rank);
						}
						
					},
					new InvocationAction() {
						@Override
						public Collection<ActionProduct> act(
								int rank, BattleActor caster,
								CastingTarget target,
								 EventParameter ep) {

							Collection<ActionProduct> product = new ArrayList<ActionProduct>();
							
							int crit = (int) (Math.random() * 100);
							Damage damageProduct = null;
							if (crit < (10 + rank)) {
								damageProduct = new Damage(caster, 
										caster.getProperTarget(target),
										(int)(((caster.getMaxDmg() - caster.getMinDmg()) * Math.random() + caster.getMaxDmg()) *3),
										ActionValueFlag.Critical,
										ActionValueElement.Holy);
							} else {
								damageProduct = new Damage(caster, 
										caster.getProperTarget(target),
										(int)(((caster.getMaxDmg() - caster.getMinDmg()) * Math.random() + caster.getMinDmg()) *2),
										ActionValueFlag.Normal,
										ActionValueElement.Holy);
							}
							
							product.add(damageProduct);
							product.add(new ConsumeMana(caster, 
									caster.getProperTarget(target),
									computeManaUse(rank)));
							product.add(new CombatLog(caster, caster.getProperTarget(CastingTarget.FocusTarget),
									caster.getName() + " [" + name + "] " + caster.getProperTarget(CastingTarget.FocusTarget).getName() + " with %p.", 
									damageProduct));
							return product;
						}
					}));
	}

	private int computeManaUse(int rank) {
		return 6 * rank;
	}

}
